<?php

namespace Controller;

class Download {
  public function single($file) {
    $filename = ASSETS_DIR . "/" . $file;
    if (!file_exists($filename)) {
      echo "{$file} not found.";
      return;
    }
    header('Content-type: application/octet-stream');
    header('Accept-Ranges: bytes');
    header('Accept-Length: ' . filesize($filename));
    header('Content-Disposition: attachment; filename=' . basename($filename));
    readfile($filename);
    fwrite(fopen($filename, 'r'), ob_get_clean());
  }
}